#ifndef _STATS_H_
#define _STATS_H_

#include "include.h"
#include "sniffing.h"

typedef struct stat_node
{
	// Prochaines stats
	struct stat_node* next;	
	
	// Numéro de paquet
	int packet_id;
	
	// Timestamp
	struct timeval timestamp;
	
	// Informations Ethernet
	char eth_src[INET6_ADDRSTRLEN];
	char eth_dst[INET6_ADDRSTRLEN];
	u_short eth_type;
	
	// Information IP
	int is_ipv4;
	u_short ipv4_id;
	char ipv4_src[INET6_ADDRSTRLEN];
	char ipv4_dst[INET6_ADDRSTRLEN];
	u_char  ipv4_proto;
	
	// Information TCP
	int is_tcp;
	u_short tcp_src;
	u_short tcp_dst;
	
	// Information UDP
	int is_udp;
	u_short udp_src;
	u_short udp_dst;
	
	// Information IPv6
	int is_ipv6;
	char     ipv6_src[INET6_ADDRSTRLEN];
	char     ipv6_dst[INET6_ADDRSTRLEN];
	u_int8_t ipv6_nh;
}
sniff_stat;

sniff_stat* add_new_node(sniff_stat* current);
void        generate_stats(sniff_stat* stats, struct timeval* begin, struct timeval* end);
void        free_stats(sniff_stat* stats);

typedef struct
{
	gint* trafic_type;
	gint* value;
}
trafic;

typedef struct 
{
	int nb_packets;
	long duration;
}
network_trafic;

void add_key(GHashTable* current, int key);

gint compare_trafic(gconstpointer a, gconstpointer b);

void foreach_trafic_ethernet(gpointer key, gpointer value, gpointer user_data);
void foreach_trafic_ipv4(gpointer key, gpointer value, gpointer user_data);
void foreach_trafic_tcp(gpointer key, gpointer value, gpointer user_data);
void foreach_trafic_udp(gpointer key, gpointer value, gpointer user_data);
void foreach_trafic_ipv6(gpointer key, gpointer value, gpointer user_data);

long  difftime_ms(struct timeval* newer, struct timeval* older);
void  print_duration(float duration);
float proportion(int a, int b);
float flow(int nb, int duration);

void generate_graph(sniff_stat* stats);

#endif
